package com.venus.lms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.venus.lms.mapper.BookMapper;
import com.venus.lms.pojo.Book;
import com.venus.lms.service.BookService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author DQM
 */
@Service
@Transactional
public class BookServiceImpl extends ServiceImpl<BookMapper, Book> implements BookService {
    @Override
    public void deleteBatchIds(List<Integer> ids) {
        baseMapper.deleteBatchIds(ids);
    }

    @Override
    public Book getBookByIsbn(String isbn) {
        LambdaQueryWrapper<Book> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(Book::getIsbn, isbn);
        return baseMapper.selectOne(wrapper);
    }

    @Override
    public Book getBookByIsbn(String isbn, Integer id) {
        LambdaQueryWrapper<Book> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(Book::getIsbn, isbn).ne(Book::getId, id);
        return baseMapper.selectOne(wrapper);
    }

    @Override
    public Book getBookById(Integer id) {
        LambdaQueryWrapper<Book> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(Book::getId, id);
        return baseMapper.selectOne(wrapper);
    }

    @Override
    public void deleteById(Long id) {
        baseMapper.deleteById(id);
    }

    @Override
    public Page<Book> selectPage(Page<Book> bookPage, LambdaQueryWrapper<Book> wrappers) {
        return baseMapper.selectPage(bookPage, wrappers);
    }
}
